<template>
	<view class="user clearfix  hv100 ">
		<cu-custom bgColor="bg-white" isBack>
			<block slot="content">{{typename[type]}}转换余额</block>
		</cu-custom>
		<view class="paylines"></view>
		<view class="flex flex-direction bg-white px15 ">
			<view class="py10">{{typename[type]}}转换余额</view>
			<view class="flex align-center justify-between py15">
				<input v-model="money" class="f14" type="number" placeholder="请输入需要转换的余额" />
				<text>元</text>
			</view>
			<view class="payline"></view>
			<view class="flex align-center justify-between py15 f12">
				<view class="flex align-center">
					<text>可用{{typename[type]}}</text>
					<text class="mx5"> {{balance}}元，</text>
					<text class="text-red" @click="money=balance">全部</text>
				</view>
				<text>手续费 {{shouxufei}}%</text>
			</view>
			<view class="py10 ">可获得</view>
			<view class="flex align-center justify-between">
				<text class="text-red f26">{{shiMoney}}</text>
				<text>元</text>
			</view>
			<view class="payline mt15"></view>
			<view class="py10 mt15">支付密码</view>
			<input maxlength="6" v-model="paypwd" class="f14" password placeholder="请输入支付密码" />
			<view class="payline mt15"></view>
		</view>
		
		<view class="red-button discenter" @click="zye">确认</view>
	</view>
</template>

<script>
import { mapState, mapActions } from 'vuex'
export default {
	data() {
		return {
			money:'',
			radio:1,
			balance:'0.00',
			shouxufei:'0',
			type:'',
			paypwd:'',
			typename:['','粮票','','分红','金种子','拼团余额']
		}
	},
	onLoad(e) {
		this.type=e.type
		this.getData()
	},
	computed:{
		shiMoney(){
			if(this.money==''||this.money==0){
				return '0.00'
			}else{
				return (this.money*this.radio*(1-this.shouxufei*0.01)).toFixed(4)
			}
		}
	},
	methods: { 
		async getData() {
			if(this.type=='4'){
				let {
					data:{num,sxfBl}
				} = await this.$http.post('wallet.yuliyuepage', {}, { tipConfig: { storeBlock: true } })
				this.balance=num
				this.shouxufei=sxfBl
			}else{
				let {
					data:{yueNum,sxfBl}
				} = await this.$http.post('wallet.fenhongyuePage', {}, { tipConfig: { storeBlock: true } })
				this.balance=yueNum
				this.shouxufei=sxfBl
			}
		},
		async zye() {
			if(this.money==''||this.money==0){
				uni.showToast({
					title:'请输入转换数量',
					icon:"none"
				})
				return false
			}
			if(this.paypwd==''){
				uni.showToast({
					title:'请输入支付密码',
					icon:"none"
				})
				return false
			}
			let params={
				ylbNum:this.money,
				payPassword:this.paypwd,
			}
			if(this.type=='4'){
				let {data} = await this.$http.post('wallet.yuliyuesure', params, { tipConfig: { storeLoading: true, isSuccessTip: true, isSuccessBack: true, navigateBack: 1 } })
			}else{
				let {data} = await this.$http.post('wallet.fenhongyue', params, { tipConfig: { storeLoading: true, isSuccessTip: true, isSuccessBack: true, navigateBack: 1 } })
			}
		},
		
	}
}
</script>

<style lang="less">
page{
	background-color: #FFFFFF;
}
.payline{
	width: 100%;
	height: 2rpx;
	background-color: #F2F2F2;
}
.paylines{
	width: 100%;
	height: 10rpx;
	background-color: #F2F2F2;
}
.red-button{
	width: calc(100% - 60rpx);
	margin-left: 30rpx;
	height: 90rpx;
	border-radius: 10rpx;
	background-color: #D73329;
	color: #FFFFFF;
	margin-top:80rpx ;
}
</style>
